<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

if ($_REQUEST["agent_id"]) 
{
	$agent_id = strip_tags($_REQUEST["agent_id"]);
	//file_put_contents  ( "param_id.txt", $agent_id);	
	
	$query = $db_query = sprintf("SELECT c.checklist_id, c.agent_id, c.checklist_item_id, 
				c.status_id, c.created, c.modified, c.created_by, c.modified_by, 
        		i.item_name checklist_item, s.item_name status 
	FROM agent_checklist c
  		INNER JOIN lk_glossary i ON c.checklist_item_id = i.item_id
  		INNER JOIN lk_glossary s ON c.status_id = s.item_id
	WHERE c.deleted = 0 AND c.agent_id ='".$agent_id."'");
	
	$items = mysql_query($query);	
}

$dom = new DomDocument('1.0',"UTF-8");
$dom->formatOutput = true;
$root = $dom->createElement( "results" );
$dom->appendChild( $root );
	while(($item = mysql_fetch_assoc($items)))
	{
		$dn = $dom->createElement( "record" );
		$dn->setAttribute( 'agent_id', ($item['agent_id']));
		$dn->setAttribute( 'checklist_id', ($item['checklist_id']));
		$dn->setAttribute( 'checklist_item_id', ($item['checklist_item_id']));
		$dn->setAttribute( 'checklist_item', ($item['checklist_item']));
		$dn->setAttribute( 'status_id', ($item['status_id']));
		$dn->setAttribute( 'status', ($item['status']));
		$dn->setAttribute( 'created', ($item['created']));
		$dn->setAttribute( 'modified', ($item['modified']));
		$dn->setAttribute( 'created_by', ($item['created_by']));
		$dn->setAttribute( 'modified_by', ($item['modified_by']));
		$root->appendChild( $dn );
	}		
header( "Content-type: text/xml; charset=UTF-8");
echo $dom->saveXML();

?>
	
